package com.physics.mps.entity.vo;

import com.physics.mps.entity.enums.CodeEnum;
import lombok.Data;

/**
 * @author mcsoft
 * @since 2023/2/8
 */
@Data
public class ResponseResult {

    // ~ 变量常量
    // =================================================================

    public final static int SUCCESS_CODE = 0;


    public final static String SUCCESS_MSG = "操作成功";

    public final static int ERROR_CODE = -1;

    private int code;

    private String message;

    private Object data;

    private Object error;

    private Throwable throwable ;

    // ~ 公有方法
    // =================================================================

    public static ResponseResult success() {
        return success(SUCCESS_MSG, null);
    }

    public static ResponseResult success(String message) {
        return success(null, message);
    }


    public static ResponseResult success(Object data) {
        return success(data, null);
    }

    public static ResponseResult success(Object data, String message) {
        ResponseResult result = new ResponseResult();
        result.setData(data);
        result.setMessage(message);
        result.setCode(SUCCESS_CODE);
        return result;
    }


    public static ResponseResult error(Object error, String message) {
        return error(error, message, ERROR_CODE);
    }


    public static ResponseResult error(Object error, String message, int code) {
        ResponseResult responseResult = error(message);
        responseResult.error = error;
        responseResult.code = code;
        return responseResult;
    }


    public static ResponseResult error(String message) {
        return error(message, ERROR_CODE);
    }

    public static ResponseResult error(CodeEnum codeEnum) {
        return error(codeEnum.getMessage(), codeEnum.getCode());
    }

    public static ResponseResult error(String message, int code) {
        ResponseResult result = new ResponseResult();
        result.setMessage(message);
        result.setCode(code);
        return result;
    }

    public static ResponseResult error(CodeEnum codeEnum, Throwable throwable) {
        ResponseResult result = error(codeEnum.getMessage(), codeEnum.getCode());
        result.throwable = throwable ;
        return result ;
    }

}

